package com.lucky.controller;

import com.lucky.annotation.Authority;
import com.lucky.annotation.SystemLog;
import com.lucky.pojo.vo.Greeting;
import com.lucky.pojo.vo.User;
import com.lucky.service.UserService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @Description
 * @Author Jalyson
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2019/6/26 18:38
 */
@RestController
@RequestMapping("/jmeter")
public class JmeterController {

    /**
     * 问候模板
     */
    private static final String template = "Hello, %s!";
    /**
     * 计数器
     */
    private final AtomicLong counter = new AtomicLong();

    @Resource(name = "userService")
    private UserService userService;

    @Authority(permission = false)
    @RequestMapping("/hello")
    public Greeting hello(@RequestParam(value = "name", defaultValue = "认证用户") String name) {
        return new Greeting(counter.incrementAndGet(), String.format(template, name));
    }

    @Authority(role = { "manager" })
    @RequestMapping("/users")
    public Collection<User> getData(String token) {
        Collection<User> all = userService.findAll();
        return all;
    }

    @Authority(permission = false)
    @RequestMapping("/user/{id}")
    public User get(@PathVariable Long id) {
        return userService.get(id);
    }

}